<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>添加账号</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
		<script type="text/javascript" src="/static/js/jquery.min.js"></script>
		<script type="text/javascript" src="/static/js/jquery.form.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" id="signupForm" action="{:url('admin/account/editadmin')}" method="post">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>账号设置
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" name="account" required="" lay-verify="required" class="layui-input" value="{$admin.account}"/>
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登入名
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">员工姓名</label>
                      <div class="layui-input-inline">
                          <input type="text" name="nkname"class="layui-input" value="{$admin.nkname}"/>
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">手机号</label>
                      <div class="layui-input-inline">
                          <input type="text" name="phone"class="layui-input" value="{$admin.phone}"/>
                      </div>
                  </div>
				  {if condition="$shopid eq 0"}
				  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">所在部门</label>
                        <div class="layui-input-inline">
                            <select name="shop_id">
								<option value="0">总部</option>
                                {volist name="shop" id="vo"}
								<option value="{$vo.shop_id}" {if condition="$admin.shop_id eq $vo.shop_id"}selected{/if}>{$vo.shop_name}</option>
                                {/volist}
							</select>
                        </div>
                   </div>
				   {else /}
					<input type="hidden" name="shop_id" value="{$shopid}"/>			
					{/if}
				   <div class="layui-form-item">
                        <label for="username" class="layui-form-label">职位</label>
                        <div class="layui-input-inline">
                            <select name="admin_type" lay-filter="admin_type">
								{if condition="$shopid eq 0"}
                                <option value="0" {if condition="$admin.admin_type eq '0'"}selected{/if}>总部</option>
                                <option value="1" {if condition="$admin.admin_type eq '1'"}selected{/if}>店长</option>
								{/if}
								<option value="2" {if condition="$admin.admin_type eq '2'"}selected{/if}>店铺营业员</option>
								<option value="3" {if condition="$admin.admin_type eq '3'"}selected{/if}>店铺维修技术员</option>
							</select>
                        </div>
                   </div>
				   <div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea placeholder="请输入内容" name="remarks" class="layui-textarea">{$admin.remarks}</textarea>
						</div>
					</div>
                  <div class="layui-form-item">
                      <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                      <div class="layui-input-block" id="role">
						{volist name="group" id="vo"}
                         <input type="checkbox" name="role[]" {if condition="$vo.checked eq 'true'"}checked{/if} lay-skin="primary" title="{$vo.title}" value="{$vo.agid}"/>
						{/volist}
					  </div>
                  </div>
                  <div class="layui-form-item">
                      <div class="layui-input-block" style="color:red;">注：默认密码为123456</div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
						<input type="hidden" name="aid" value="{$admin.admin_id}"/>
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">修改</button>
                  </div>
              </form>
            </div>
        </div>
        <script>
		var flag = true;
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
		  //监听select
			form.on('select(admin_type)',
			function(data) {
				var params = {};
				params.admin_type = data.value;
				$.ajax({
					type: "POST",
					url: "/admin/account/getThisGroup.html",
					cache: false, //禁用缓存
					data: params, //传入组装的参数
					dataType: "json",
					success: function (result) {
						console.log(result);
						var i;
						var str = '';
						for (i in result) {
							str += '<input type="checkbox" name="role[]" lay-skin="primary" title="'+result[i].title+'" value="'+result[i].agid+'"/>';
						}
						$('#role').html(str);
						form.render('checkbox');
					},
					error:function () {
						parent.layer.msg('网络错误', {icon: 5});
					}
				})
			});
			//监听提交
			form.on('submit(add)',
			function(data) {
				if(flag)
				{
					flag = false;
					$("#signupForm").ajaxSubmit(function (message) {
						 if(message.code == 10001)
						 {
							layer.msg("修改成功", {
								icon: 6
							},
							function() {
								//关闭当前frame
								xadmin.close();
								// 可以对父窗口进行刷新 
								xadmin.father_reload();
							});
						 }else if(message.code == 10003){
							layer.msg("请选择角色", {
								icon: 5
							},
							function() {
								flag = true;
							});
						 }else{
							layer.msg(message.msg, {
								icon: 5
							},
							function() {
								//关闭当前frame
								xadmin.close();
								// 可以对父窗口进行刷新 
								xadmin.father_reload();
							});
						 }
					});
				}else{
					layer.msg('正在提交。。。', {icon: 6});
				}
				return false;
			});
        });
    </script>
    </body>

</html>
